class SaveFileAction < WorkflowAction
  validates_presence_of :filename
  
  def valid_input_classes
    [String]
  end  
  
  def output_class
    File
  end
  
  def timestamp_format
    options[:timestamp_format] || "%Y-%m-%d_%H-%m-%S"
  end
  
  def timestamp(format=timestamp_format)
    Time.now.strftime(format)
  end
  
  def filename
    name = options[:filename]
    name.sub!(/\.([^.]+$)/, "_#{timestamp}.\\1") if add_timestamp
    name
  end
  
  def execute
    file = File.new(filename, 'w')
    file << input
    file.close
    @output = File
  end
end